{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 6.13 \u6570\u636e\u7684\u7d2f\u52a0\u4e0e\u7edf\u8ba1\u64cd\u4f5c\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u9700\u8981\u5904\u7406\u4e00\u4e2a\u5f88\u5927\u7684\u6570\u636e\u96c6\u5e76\u9700\u8981\u8ba1\u7b97\u6570\u636e\u603b\u548c\u6216\u5176\u4ed6\u7edf\u8ba1\u91cf\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5bf9\u4e8e\u4efb\u4f55\u6d89\u53ca\u5230\u7edf\u8ba1\u3001\u65f6\u95f4\u5e8f\u5217\u4ee5\u53ca\u5176\u4ed6\u76f8\u5173\u6280\u672f\u7684\u6570\u636e\u5206\u6790\u95ee\u9898\uff0c\u90fd\u53ef\u4ee5\u8003\u8651\u4f7f\u7528 Pandas\u5e93 \u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4e3a\u4e86\u8ba9\u4f60\u5148\u4f53\u9a8c\u4e0b\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Pandas\u6765\u5206\u6790\u829d\u52a0\u54e5\u57ce\u5e02\u7684\n\u8001\u9f20\u548c\u556e\u9f7f\u7c7b\u52a8\u7269\u6570\u636e\u5e93 \u7684\u4f8b\u5b50\u3002\n\u5728\u6211\u5199\u8fd9\u7bc7\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u6570\u636e\u5e93\u662f\u4e00\u4e2a\u62e5\u6709\u5927\u698274,000\u884c\u6570\u636e\u7684CSV\u6587\u4ef6\u3002"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Read a CSV file, skipping last line\nrats = pandas.read_csv('rats.csv', skip_footer=1)\nrats"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Investigate range of values for a certain field\nrats['Current Activity'].unique()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Filter the data\ncrew_dispatched = rats[rats['Current Activity'] == 'Dispatch Crew']\nlen(crew_dispatched)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Find 10 most rat-infested ZIP codes in Chicago\ncrew_dispatched['ZIP Code'].value_counts()[:10]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Group by completion date\ndates = crew_dispatched.groupby('Completion Date')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "len(dates)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Determine counts on each day\ndate_counts = dates.size()\ndate_counts[0:10]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Sort the counts\ndate_counts.sort()\ndate_counts[-10:]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u55ef\uff0c\u770b\u6837\u5b502011\u5e7410\u67087\u65e5\u5bf9\u8001\u9f20\u4eec\u6765\u8bf4\u662f\u4e2a\u5f88\u5fd9\u788c\u7684\u65e5\u5b50\u554a\uff01^_^"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Pandas\u662f\u4e00\u4e2a\u62e5\u6709\u5f88\u591a\u7279\u6027\u7684\u5927\u578b\u51fd\u6570\u5e93\uff0c\u6211\u5728\u8fd9\u91cc\u4e0d\u53ef\u80fd\u4ecb\u7ecd\u5b8c\u3002\n\u4f46\u662f\u53ea\u8981\u4f60\u9700\u8981\u53bb\u5206\u6790\u5927\u578b\u6570\u636e\u96c6\u5408\u3001\u5bf9\u6570\u636e\u5206\u7ec4\u3001\u8ba1\u7b97\u5404\u79cd\u7edf\u8ba1\u91cf\u6216\u5176\u4ed6\u7c7b\u4f3c\u4efb\u52a1\u7684\u8bdd\uff0c\u8fd9\u4e2a\u51fd\u6570\u5e93\u771f\u7684\u503c\u5f97\u4f60\u53bb\u770b\u4e00\u770b\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}